//
//  JZHConcernedResourceViewController.m
//  极致荟
//
//  Created by hetao on 14-5-7.
//  Copyright (c) 2014年 mac. All rights reserved.
//

#import "JZHConcernedResourceViewController.h"
#import "JZHConcernedResourceCell.h"
@interface JZHConcernedResourceViewController ()
{
    NSMutableArray *nameList;
}
@property (weak, nonatomic) IBOutlet UITableView *table;

@end

@implementation JZHConcernedResourceViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self setNavigation];
    if(OSVersionIsAtLeastiOS7>=7.0)
    {
        self.automaticallyAdjustsScrollViewInsets=NO;
    }
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
//导航条设置
-(void)setNavigation
{
    //设置导航视图title
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 44)];
    [titleLabel setTextColor:[UIColor blackColor]];
    [titleLabel setTextAlignment:NSTextAlignmentCenter];
    titleLabel.font = [UIFont boldSystemFontOfSize:16];
    titleLabel.text = @"定制关注的资源";
    self.navigationItem.titleView= titleLabel;
    
    
    //设置左侧按钮
    UIButton *leftButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 12, 20)];
    [leftButton addTarget:self action:@selector(leftDrawerButtonPress:) forControlEvents:UIControlEventTouchUpInside];
    [leftButton setImage:[UIImage imageNamed:@"返回"] forState:UIControlStateNormal];
    UIBarButtonItem *leftBarButton = [[UIBarButtonItem alloc] initWithCustomView:leftButton];
    self.navigationItem.leftBarButtonItem = leftBarButton;
    [self httpLoad];
}

- (void)httpLoad
{
    if([User defuceUser].focusType.ftdic)
    {
        return;
    }
    //[MMProgressHUD showWithStatus:@"数据加载中..."];
    [HttpRequest httpRequestPost:JZHHTTPURL(@"attention/attentionCategory") parameters:nil block:^(id data, HttpReturnCode rerurncode) {
        if(rerurncode==0)
        {
            [MMProgressHUD dismiss];
            [User defuceUser].focusType.ftdic=[data objectForKey:@"data"];
            [self.table reloadData];
        }else
        {
            [MMProgressHUD  showInformationWithTips:@"数据加载失败"];
        }
    }];
}
- (void)leftDrawerButtonPress:(UIButton *)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}
#pragma mark-------TableView代理----------
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;

{
    if([User defuceUser].focusType.ftdic)
    {
        return [User defuceUser].focusType.ftdic.count;
    }
    return 0;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 44;
    
    
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *pengyoucell=@"PengyouCell";
    
    JZHConcernedResourceCell *cell=[tableView dequeueReusableCellWithIdentifier:pengyoucell];
    if(!cell)
    {
        cell=[[[NSBundle mainBundle] loadNibNamed:@"JZHConcernedResourceCell" owner:self options:nil] objectAtIndex:0];
    }
    [cell.text setText:[[User defuceUser].focusType.ftdic[indexPath.row] objectForKey:@"name"]];
    [cell.image.layer setCornerRadius:4.0];
    [cell.image.layer setMasksToBounds:YES];
    return cell;
    
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
   JZHConcernedResourceCell *cell= (JZHConcernedResourceCell*)[tableView cellForRowAtIndexPath:indexPath];
    [cell.image setBackgroundColor:[UIColor blackColor]];
    [cell.contentView setBackgroundColor:[UIColor whiteColor]];
    [User defuceUser].focusType.selectft=[User defuceUser].focusType.ftdic[indexPath.row];
    for(int i=0;i<[User defuceUser].focusType.ftdic.count;i++)
    {
         NSIndexPath *ind=[NSIndexPath indexPathForRow:i inSection:0];
        if(i!=indexPath.row)
        {
            cell=(JZHConcernedResourceCell*)[tableView cellForRowAtIndexPath:ind];
              [cell.image setBackgroundColor:[UIColor grayColor]];
        }
    }
   
   
    //[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
@end
